function delay(duration) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      reject();
    }, duration);
  });
}

/* 以前的写法 */
delay(1000).then((res)=>{
    console.log('成功了');
},err=>{
    console.log('失败了');
})

/* 利用自执行函数，执行上面异步delay函数 */
(async () => {
  try {
    const res = await delay(1000);
    console.log(res);
  } catch (error) {
    console.log('失败了',error);
  }
})();
